package cn.bluemobi.app.controller.address;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.app.core.controller.AppBaseController;
import cn.bluemobi.app.entity.form.AddressForm;
import cn.bluemobi.app.entity.output.Address;
import cn.bluemobi.app.service.AddressService;
import cn.bluemobi.common.core.dto.Dto;
import cn.bluemobi.common.core.dto.ListDto;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/address")
@Api(description = "收货地址", value = "address")
public class AddressController extends AppBaseController {

	@Autowired
	private AddressService addressService;

	@ApiOperation(value = "查询所有地址", httpMethod = "POST")
	@RequestMapping("/findAllAddress")
	@ResponseBody
	public ListDto<Address> findAllAddress(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId) {
		return addressService.findAllAddress(memberId);
	}

	@ApiOperation(value = "添加或者编辑地址", httpMethod = "POST")
	@RequestMapping("/saveOrUpdateAddress")
	@ResponseBody
	public Dto<Object> saveOrUpdateAddress(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@RequestBody AddressForm addressForm) {
		return addressService.saveOrUpdateAddress(memberId, addressForm);
	}

	@ApiOperation(value = "删除地址", httpMethod = "POST")
	@RequestMapping("/deleteAddress")
	@ResponseBody
	public Dto<Object> deleteAddress(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId,
			@ApiParam("地址ID") @RequestParam("addressId") String addressId) {
		return addressService.deleteAddress(memberId, addressId);
	}

	@ApiOperation(value = "查询默认地址", httpMethod = "POST")
	@RequestMapping("/findDefaultAddress")
	@ResponseBody
	public Dto<Address> findDefaultAddress(
			@ApiParam("会员ID") @RequestParam("memberId") String memberId) {
		return addressService.findDefaultAddress(memberId);
	}

}
